package com.ruoyi.web.controller.system;

import com.ruoyi.common.utils.COSUtil;
import com.ruoyi.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/system/oss")
public class SysOssUploadController {

    @Autowired
    private COSUtil cosUtil;

    /**
     * 上传图片
     */
    @PostMapping("/upload")
    public Result<Map<String, String>> upload(@RequestParam("file") MultipartFile multipartFile)
    {
        String url = cosUtil.uploadFile(multipartFile);
        Map<String, String> res = new HashMap<>(2);
        res.put("fileName", UUID.randomUUID().toString());
        res.put("url", url);
        return Result.OK(res);
    }

}
